package priv.yiyuan.example.design.adapter;

/**
 * 原始多媒体实现类
 * <p>
 * 加入适配器工厂方法的引用
 *
 * @author YiYuan
 * @data 2025/8/5
 * @apoNote
 */
public class AudioPlayer implements MediaPlayer {

    private MediaAdapterFactory adapterFactory;

    /**
     * 构造函数 初始化 适配器工厂类
     *
     * @param adapterFactory
     */
    public AudioPlayer(MediaAdapterFactory adapterFactory) {
        this.adapterFactory = adapterFactory;
    }

    @Override
    public void play(String audioType, String fileName) {

        if (audioType.equalsIgnoreCase("mp3")) {
            System.out.println("Playing mp3 file. Name: " + fileName);
        }
        else {
            MediaPlayer adapter = adapterFactory.createAdapter(audioType);

            if (adapter != null) {
                adapter.play(audioType, fileName);
            }
            else {
                System.out.println("Invalid media. " + audioType + " format not supported");
            }
        }

    }
}
